package xxx.core.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import xxx.common.enums.BizStatusEnum;
import xxx.core.repository.mapper.StudentMapper;
import xxx.pojo.entity.Student;

/**
 * @author yuanchengman
 * @date 2021-08-16
 */
@Repository
public class StudentRepository extends ServiceImpl<StudentMapper, Student> {

    @Autowired
    private StudentMapper mapper;

    public Student getByName(String studentName) {
        LambdaQueryWrapper<Student> queryWrapper = new LambdaQueryWrapper<Student>()
                .eq(Student::getName, studentName)
                .eq(Student::getBizStatus, BizStatusEnum.NORMAL.getCode())
                .last("limit 1");
        return mapper.selectOne(queryWrapper);
    }

    public void updateByName(String studentName, Integer gender){
        LambdaUpdateWrapper<Student> updateWrapper = new LambdaUpdateWrapper<Student>()
                .eq(Student::getName, studentName)
                .set(Student::getGender, gender);

        mapper.update(null, updateWrapper);
    }
}
